package niumao.minecraft.uhc.listener;

import niumao.minecraft.uhc.Main;
import niumao.minecraft.uhc.Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;

public class anduril_miner {
    public static void runnablerunner() {
        new BukkitRunnable() {
            @Override
            public void run() {
                for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                    if (player == null) return;
                    ItemStack item = player.getInventory().getItemInMainHand();
                    ItemMeta itemMeta = item.getItemMeta();
                    if (itemMeta == null) return;
                    if (itemMeta.getDisplayName().equals(Util.getStr("Miner"))) {
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 30, 2), true);
                    }
                    if (itemMeta.getDisplayName().equals(Util.getStr("Anduril"))) {
                        player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 30, 0), true);
                        player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 30, 0), true);
                    }
                }
            }

        }.runTaskTimer(Main.getInstance(), 0L, 20L);
    }
}
